package com.wlps.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.wlps.result.ResultPageVo;

import java.util.ArrayList;
import java.util.List;

public class PageUtils<T> {
    public static<T>  ResultPageVo<T> getPageInfo(IPage<T> page){
        ResultPageVo<T> tResultPageVo = new ResultPageVo<>();
        tResultPageVo.setMsg("获得信息成功");
        tResultPageVo.setMsg("200");
        //返回数据总条数
        tResultPageVo.setTotal((page.getTotal()));
        //返回数据有多少页x
        tResultPageVo.setPageNum(page.getPages());
        //返回数据每页多少条数据
        tResultPageVo.setPageSize(( page.getTotal()));
        //返回数据
        tResultPageVo.setData((T) page.getRecords());
        return tResultPageVo;
    }

    public static<T>  ResultPageVo<T> getPageInfo(List<T> list){

        PageInfo<T> tPageInfo = new PageInfo<>(list);
        ResultPageVo<T> tResultPageVo = new ResultPageVo<>();
        tResultPageVo.setMsg("获得信息成功");
        tResultPageVo.setCode(200);
        tResultPageVo.setData((T) tPageInfo.getList());
        tResultPageVo.setPageNum((long) tPageInfo.getPageNum());
        tResultPageVo.setPageSize((long) tPageInfo.getPageSize());
        tResultPageVo.setTotal((long) tPageInfo.getSize());
        return tResultPageVo;
    }

}
